        @if(isset($model))
	{!! Form::model($model, ['method' => 'PUT', 'files' => true, 'route' => ['admin.purchase.update', $model->id]]) !!}
	@else
	{!! Form::open(['route' => 'admin.purchase.store']) !!}
	@endif
 <div class="form-inline">
	<div class="form-group">
		{!! Form::label('codeno', '进货单号:') !!}
		{!! Form::text('codeno', isset($model)?null:'LN'.date('YmdHis'), ['class' => 'form-control']) !!}
		{!! $errors->first('codeno', '<div class="text-danger">:message</div>') !!}
	</div>
        <div class="form-group">
		{!! Form::label('company', '供应商:') !!}
		{!! Form::text('company', null, ['class' => 'form-control']) !!}
		{!! $errors->first('company', '<div class="text-danger">:message</div>') !!}
	</div>
            
        <div class="form-group">
		{!! Form::label('created_at', '进货日期:') !!}
		{!! Form::text('created_at', date("Y-m-d"), ['class' => 'form-control']) !!}
		{!! $errors->first('created_at', '<div class="text-danger">:message</div>') !!}
	</div>
</div>
 
           
       
        <br/>
         <div class="box box-success">
            <div class="box-header ui-sortable-handle" >
				<i class="fa fa-glass"></i>

				<h3 class="box-title">产品列表</h3>
				<div class="pull-right box-tools">
                                    <button class="btn btn-info btn-sm" id="add_goods" type="button"><i class="fa fa-plus-circle"></i>选择产品</button>
				</div>
            </div>
            <div class="box-body">
       
                    <div class="row">
                    <div class="col-xs-3">
                             <div class="typeahead-container">
                                    <div class="typeahead-field ">

                                        <span class="typeahead-query">
                                            {!! Form::text('goodsinfo', null, ['class' => 'form-control','id'=>'goodsinfo','autocomplete'=>'off','placeholder'=>'请输入产品名称/货号,选择后,按Enter']) !!}
                                        </span>


                                    </div>
                                </div> 
                        
                    </div>
                    </div>
                   <table class="table">
		<thead>
                <th class="text-center">图片</th>
			<th class="text-center">型号/规格</th>
			<th class="text-center">数量</th>
                        <th class="text-center">金额(￥)元</th>
                        <th class="text-center">合计(￥)元</th>
			<th class="text-center">操作</th>
		</thead>
                <tbody id="goodslist">
                    @if(isset($model))
                    @foreach($model->purchase_item as $v)
                    <tr id="{!! $v->goods_id !!}">
                        <td class="text-center">
                            <img src="{!! thumber(60,$v->goods->image) !!}"/>
                        </td>
                        <td class="text-center">
                            {!! $v->goods->name !!}/{!! $v->goods->codeno !!}
                        </td>
                        <td class="text-center">
                            <div style="width:70px;margin:auto;"><input class="form-control ship_nums" name="goods[{!! $v->goods_id !!}][purchase_nums]" type="text" value="{!! $v->purchase_nums !!}" onblur="jponblur(this,'purchase')" /></div>
                        </td>
                        <td class="text-center">
                            <div style="width:80px;margin:auto;"><input class="form-control ship_price" onblur="jponblur(this,'purchase')" name="goods[{!! $v->goods_id !!}][purchase_price]" type="text" value="{!! $v->purchase_price !!}" /></div>
                        </td>
                        <td class="text-success text-center">
                            <b><span class="jpzj">{!! $v->purchase_price*$v->purchase_nums !!}</span>元</b>
                        </td>
                        <td class="text-center" style="font-size:24px;">
                            <i class="fa fa-times-circle-o" onclick="del_good(this)" style="cursor:pointer;"></i>
                        </td>
                    </tr>
                    @endforeach
                    @endif
                </tbody>
                <tfoot>
                    <tr>
                        <td colspan="7">
                            <div class="text-bold text-success content"><span>进货总数：<span class="allnums">@if(isset($model)) {!! $model->purchase_nums !!} @else 0 @endif</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;总金额:<span class="allprice">@if(isset($model)) {!! $model->all_price !!} @else 0 @endif</span>￥</span></div>
                        </td>
                   </tr>
                </tfoot>
                    </table>
                {!! $errors->first('goods', '<div class="text-danger">:message</div>') !!}
                    
                 
      
            </div>
         </div>
        
         <div class="form-group">
                {!! Form::label('remark', '备注:') !!}
		{!! Form::textarea('remark', null, ['class' => 'form-control']) !!}
		{!! $errors->first('remark', '<div class="text-danger">:message</div>') !!}
            </div>
        
	<div class="form-group">
		{!! Form::submit(isset($model) ? '更新' : '保存', ['class' => 'btn btn-primary','id'=>'submit']) !!}
	</div>
{!! Form::close() !!}
@section('script')
<script src="{!! admin_asset('js/goodstypeahead.js') !!}"></script>
<script>
$(function() {
           getgoodslist('goodsinfo','{!! route('ajaxgoodslist') !!}');
           bindgoodsclick('goodsinfo','goodslist','{!! route('ajaxgetgood') !!}',$('meta[name="_token"]').attr('content'),'no','purchase');
           $("input[name='created_at']").datepicker({
                format: 'yyyy-mm-dd'
            });
           
        });
</script>

@endsection
